package com.example.mbl.controller;

import com.example.mbl.entity.Book;
import com.example.mbl.interceptor.AppToken;
import com.example.mbl.result.PageResult;
import com.example.mbl.result.WebRestResult;
import com.example.mbl.result.business.BookPageResult;
import com.example.mbl.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("Book")
public class BookController {
    @Autowired
    private BookService bookService;

    @AppToken
    @PostMapping("addBook")
    public WebRestResult addBook(@RequestBody Book book){
        WebRestResult result = bookService.addBook(book);
        return result;
    }

    @AppToken
    @PostMapping("deleteBook")
    public WebRestResult deleteBook(@RequestBody Book book){
        WebRestResult result = bookService.deleteBook(book);
        return result;
    }

    @AppToken
    @PostMapping("updateBook")
    public WebRestResult updateBook(@RequestBody Book book){
        WebRestResult result = bookService.updateBook(book);
        return result;
    }

    @AppToken
    @PostMapping("setBookVisible")
    public WebRestResult setBookVisible(@RequestBody Book book){
        WebRestResult result = bookService.setBookVisible(book);
        return result;
    }

    @GetMapping("getBookList")
    public PageResult<BookPageResult> getBookList(String bookname,String publishdate,int page,int pagesize){
        PageResult<BookPageResult> result = bookService.getBookList(bookname,publishdate,page,pagesize);
        return result;
    }
}
